home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-31.z / elisp-31 (.txt)
GNU Info File  |  1998-05-26  |  50KB  |  921 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Output from Processes,  Next: Sentinels,  Prev: Signals to Processes,  Up: Processes
  32. Receiving Output from Processes
  33. ===============================
  34.    There are two ways to receive the output that a subprocess writes to
  35. its standard output stream.  The output can be inserted in a buffer,
  36. which is called the associated buffer of the process, or a function
  37. called the "filter function" can be called to act on the output.  If
  38. the process has no buffer and no filter function, its output is
  39. discarded.
  40. * Menu:
  41. * Process Buffers::       If no filter, output is put in a buffer.
  42. * Filter Functions::      Filter functions accept output from the process.
  43. * Accepting Output::      Explicitly permitting subprocess output.
  44.                             Waiting for subprocess output.
  45. File: elisp,  Node: Process Buffers,  Next: Filter Functions,  Up: Output from Processes
  46. Process Buffers
  47. ---------------
  48.    A process can (and usually does) have an "associated buffer", which
  49. is an ordinary Emacs buffer that is used for two purposes: storing the
  50. output from the process, and deciding when to kill the process.  You
  51. can also use the buffer to identify a process to operate on, since in
  52. normal practice only one process is associated with any given buffer.
  53. Many applications of processes also use the buffer for editing input to
  54. be sent to the process, but this is not built into Emacs Lisp.
  55.    Unless the process has a filter function (*note Filter Functions::.),
  56. its output is inserted in the associated buffer.  The position to insert
  57. the output is determined by the `process-mark', which is then updated
  58. to point to the end of the text just inserted.  Usually, but not
  59. always, the `process-mark' is at the end of the buffer.
  60.  - Function: process-buffer PROCESS
  61.      This function returns the associated buffer of the process PROCESS.
  62.           (process-buffer (get-process "shell"))
  63.                => #<buffer *shell*>
  64.  - Function: process-mark PROCESS
  65.      This function returns the process marker for PROCESS, which is the
  66.      marker that says where to insert output from the process.
  67.      If PROCESS does not have a buffer, `process-mark' returns a marker
  68.      that points nowhere.
  69.      Insertion of process output in a buffer uses this marker to decide
  70.      where to insert, and updates it to point after the inserted text.
  71.      That is why successive batches of output are inserted
  72.      consecutively.
  73.      Filter functions normally should use this marker in the same
  74.      fashion as is done by direct insertion of output in the buffer.  A
  75.      good example of a filter function that uses `process-mark' is
  76.      found at the end of the following section.
  77.      When the user is expected to enter input in the process buffer for
  78.      transmission to the process, the process marker is useful for
  79.      distinguishing the new input from previous output.
  80.  - Function: set-process-buffer PROCESS BUFFER
  81.      This function sets the buffer associated with PROCESS to BUFFER.
  82.      If BUFFER is `nil', the process becomes associated with no buffer.
  83.  - Function: get-buffer-process BUFFER-OR-NAME
  84.      This function returns the process associated with BUFFER-OR-NAME.
  85.      If there are several processes associated with it, then one is
  86.      chosen.  (Presently, the one chosen is the one most recently
  87.      created.)  It is usually a bad idea to have more than one process
  88.      associated with the same buffer.
  89.           (get-buffer-process "*shell*")
  90.                => #<process shell>
  91.      Killing the process's buffer deletes the process, which kills the
  92.      subprocess with a `SIGHUP' signal (*note Signals to Processes::.).
  93. File: elisp,  Node: Filter Functions,  Next: Accepting Output,  Prev: Process Buffers,  Up: Output from Processes
  94. Process Filter Functions
  95. ------------------------
  96.    A process "filter function" is a function that receives the standard
  97. output from the associated process.  If a process has a filter, then
  98. *all* output from that process is passed to the filter.  The process
  99. buffer is used directly for output from the process only when there is
  100. no filter.
  101.    A filter function must accept two arguments: the associated process
  102. and a string, which is the output.  The function is then free to do
  103. whatever it chooses with the output.
  104.    A filter function runs only while Emacs is waiting (e.g., for
  105. terminal input, or for time to elapse, or for process output).  This
  106. avoids the timing errors that could result from running filters at
  107. random places in the middle of other Lisp programs.  You may explicitly
  108. cause Emacs to wait, so that filter functions will run, by calling
  109. `sit-for' or `sleep-for' (*note Waiting::.), or `accept-process-output'
  110. (*note Accepting Output::.).  Emacs is also waiting when the command
  111. loop is reading input.
  112.    Quitting is normally inhibited within a filter function--otherwise,
  113. the effect of typing `C-g' at command level or to quit a user command
  114. would be unpredictable.  If you want to permit quitting inside a filter
  115. function, bind `inhibit-quit' to `nil'.  *Note Quitting::.
  116.    If an error happens during execution of a filter function, it is
  117. caught automatically, so that it doesn't stop the execution of whatever
  118. program was running when the filter function was started.  However, if
  119. `debug-on-error' is non-`nil', the error-catching is turned off.  This
  120. makes it possible to use the Lisp debugger to debug the filter
  121. function.  *Note Debugger::.
  122.    Many filter functions sometimes or always insert the text in the
  123. process's buffer, mimicking the actions of Emacs when there is no
  124. filter.  Such filter functions need to use `set-buffer' in order to be
  125. sure to insert in that buffer.  To avoid setting the current buffer
  126. semipermanently, these filter functions must use `unwind-protect' to
  127. make sure to restore the previous current buffer.  They should also
  128. update the process marker, and in some cases update the value of point.
  129. Here is how to do these things:
  130.      (defun ordinary-insertion-filter (proc string)
  131.        (let ((old-buffer (current-buffer)))
  132.          (unwind-protect
  133.              (let (moving)
  134.                (set-buffer (process-buffer proc))
  135.                (setq moving (= (point) (process-mark proc)))
  136.      (save-excursion
  137.                  ;; Insert the text, moving the process-marker.
  138.                  (goto-char (process-mark proc))
  139.                  (insert string)
  140.                  (set-marker (process-mark proc) (point)))
  141.                (if moving (goto-char (process-mark proc))))
  142.            (set-buffer old-buffer))))
  143. The reason to use an explicit `unwind-protect' rather than letting
  144. `save-excursion' restore the current buffer is so as to preserve the
  145. change in point made by `goto-char'.
  146.    To make the filter force the process buffer to be visible whenever
  147. new text arrives, insert the following line just before the
  148. `unwind-protect':
  149.      (display-buffer (process-buffer proc))
  150.    To force point to move to the end of the new output no matter where
  151. it was previously, eliminate the variable `moving' and call `goto-char'
  152. unconditionally.
  153.    In earlier Emacs versions, every filter function that did regexp
  154. searching or matching had to explicitly save and restore the match data.
  155. Now Emacs does this automatically; filter functions never need to do it
  156. explicitly.  *Note Match Data::.
  157.    A filter function that writes the output into the buffer of the
  158. process should check whether the buffer is still alive.  If it tries to
  159. insert into a dead buffer, it will get an error.  If the buffer is dead,
  160. `(buffer-name (process-buffer PROCESS))' returns `nil'.
  161.    The output to the function may come in chunks of any size.  A program
  162. that produces the same output twice in a row may send it as one batch
  163. of 200 characters one time, and five batches of 40 characters the next.
  164.  - Function: set-process-filter PROCESS FILTER
  165.      This function gives PROCESS the filter function FILTER.  If FILTER
  166.      is `nil', it gives the process no filter.
  167.  - Function: process-filter PROCESS
  168.      This function returns the filter function of PROCESS, or `nil' if
  169.      it has none.
  170.    Here is an example of use of a filter function:
  171.      (defun keep-output (process output)
  172.         (setq kept (cons output kept)))
  173.           => keep-output
  174.      (setq kept nil)
  175.           => nil
  176.      (set-process-filter (get-process "shell") 'keep-output)
  177.           => keep-output
  178.      (process-send-string "shell" "ls ~/other\n")
  179.           => nil
  180.      kept
  181.           => ("lewis@slug[8] % "
  182.      "FINAL-W87-SHORT.MSS    backup.otl              kolstad.mss~
  183.      address.txt             backup.psf              kolstad.psf
  184.      backup.bib~             david.mss               resume-Dec-86.mss~
  185.      backup.err              david.psf               resume-Dec.psf
  186.      backup.mss              dland                   syllabus.mss
  187.      "
  188.      "#backups.mss#          backup.mss~             kolstad.mss
  189.      ")
  190. File: elisp,  Node: Accepting Output,  Prev: Filter Functions,  Up: Output from Processes
  191. Accepting Output from Processes
  192. -------------------------------
  193.    Output from asynchronous subprocesses normally arrives only while
  194. Emacs is waiting for some sort of external event, such as elapsed time
  195. or terminal input.  Occasionally it is useful in a Lisp program to
  196. explicitly permit output to arrive at a specific point, or even to wait
  197. until output arrives from a process.
  198.  - Function: accept-process-output &optional PROCESS SECONDS MILLISEC
  199.      This function allows Emacs to read pending output from processes.
  200.      The output is inserted in the associated buffers or given to their
  201.      filter functions.  If PROCESS is non-`nil' then this function does
  202.      not return until some output has been received from PROCESS.
  203.      The arguments SECONDS and MILLISEC let you specify timeout
  204.      periods.  The former specifies a period measured in seconds and the
  205.      latter specifies one measured in milliseconds.  The two time
  206.      periods thus specified are added together, and
  207.      `accept-process-output' returns after that much time whether or
  208.      not there has been any subprocess output.
  209.      The argument SECONDS need not be an integer.  If it is a floating
  210.      point number, this function waits for a fractional number of
  211.      seconds.  Some systems support only a whole number of seconds; on
  212.      these systems, SECONDS is rounded down.  If the system doesn't
  213.      support waiting fractions of a second, you get an error if you
  214.      specify nonzero MILLISEC.
  215.      Not all operating systems support waiting periods other than
  216.      multiples of a second; on those that do not, you get an error if
  217.      you specify nonzero MILLISEC.
  218.      The function `accept-process-output' returns non-`nil' if it did
  219.      get some output, or `nil' if the timeout expired before output
  220.      arrived.
  221. File: elisp,  Node: Sentinels,  Next: Transaction Queues,  Prev: Output from Processes,  Up: Processes
  222. Sentinels: Detecting Process Status Changes
  223. ===========================================
  224.    A "process sentinel" is a function that is called whenever the
  225. associated process changes status for any reason, including signals
  226. (whether sent by Emacs or caused by the process's own actions) that
  227. terminate, stop, or continue the process.  The process sentinel is also
  228. called if the process exits.  The sentinel receives two arguments: the
  229. process for which the event occurred, and a string describing the type
  230. of event.
  231.    The string describing the event looks like one of the following:
  232.    * `"finished\n"'.
  233.    * `"exited abnormally with code EXITCODE\n"'.
  234.    * `"NAME-OF-SIGNAL\n"'.
  235.    * `"NAME-OF-SIGNAL (core dumped)\n"'.
  236.    A sentinel runs only while Emacs is waiting (e.g., for terminal
  237. input, or for time to elapse, or for process output).  This avoids the
  238. timing errors that could result from running them at random places in
  239. the middle of other Lisp programs.  A program can wait, so that
  240. sentinels will run, by calling `sit-for' or `sleep-for' (*note
  241. Waiting::.), or `accept-process-output' (*note Accepting Output::.).
  242. Emacs is also waiting when the command loop is reading input.
  243.    Quitting is normally inhibited within a sentinel--otherwise, the
  244. effect of typing `C-g' at command level or to quit a user command would
  245. be unpredictable.  If you want to permit quitting inside a sentinel,
  246. bind `inhibit-quit' to `nil'.  *Note Quitting::.
  247.    A sentinel that writes the output into the buffer of the process
  248. should check whether the buffer is still alive.  If it tries to insert
  249. into a dead buffer, it will get an error.  If the buffer is dead,
  250. `(buffer-name (process-buffer PROCESS))' returns `nil'.
  251.    If an error happens during execution of a sentinel, it is caught
  252. automatically, so that it doesn't stop the execution of whatever
  253. programs was running when the sentinel was started.  However, if
  254. `debug-on-error' is non-`nil', the error-catching is turned off.  This
  255. makes it possible to use the Lisp debugger to debug the sentinel.
  256. *Note Debugger::.
  257.    In earlier Emacs versions, every sentinel that did regexp searching
  258. or matching had to explicitly save and restore the match data.  Now
  259. Emacs does this automatically; sentinels never need to do it explicitly.
  260. *Note Match Data::.
  261.  - Function: set-process-sentinel PROCESS SENTINEL
  262.      This function associates SENTINEL with PROCESS.  If SENTINEL is
  263.      `nil', then the process will have no sentinel.  The default
  264.      behavior when there is no sentinel is to insert a message in the
  265.      process's buffer when the process status changes.
  266.           (defun msg-me (process event)
  267.              (princ
  268.                (format "Process: %s had the event `%s'" process event)))
  269.           (set-process-sentinel (get-process "shell") 'msg-me)
  270.                => msg-me
  271.           (kill-process (get-process "shell"))
  272.                -| Process: #<process shell> had the event `killed'
  273.                => #<process shell>
  274.  - Function: process-sentinel PROCESS
  275.      This function returns the sentinel of PROCESS, or `nil' if it has
  276.      none.
  277.  - Function: waiting-for-user-input-p
  278.      While a sentinel or filter function is running, this function
  279.      returns non-`nil' if Emacs was waiting for keyboard input from the
  280.      user at the time the sentinel or filter function was called, `nil'
  281.      if it was not.
  282. File: elisp,  Node: Transaction Queues,  Next: Network,  Prev: Sentinels,  Up: Processes
  283. Transaction Queues
  284. ==================
  285.    You can use a "transaction queue" for more convenient communication
  286. with subprocesses using transactions.  First use `tq-create' to create
  287. a transaction queue communicating with a specified process.  Then you
  288. can call `tq-enqueue' to send a transaction.
  289.  - Function: tq-create PROCESS
  290.      This function creates and returns a transaction queue
  291.      communicating with PROCESS.  The argument PROCESS should be a
  292.      subprocess capable of sending and receiving streams of bytes.  It
  293.      may be a child process, or it may be a TCP connection to a server,
  294.      possibly on another machine.
  295.  - Function: tq-enqueue QUEUE QUESTION REGEXP CLOSURE FN
  296.      This function sends a transaction to queue QUEUE.  Specifying the
  297.      queue has the effect of specifying the subprocess to talk to.
  298.      The argument QUESTION is the outgoing message that starts the
  299.      transaction.  The argument FN is the function to call when the
  300.      corresponding answer comes back; it is called with two arguments:
  301.      CLOSURE, and the answer received.
  302.      The argument REGEXP is a regular expression that should match the
  303.      entire answer, but nothing less; that's how `tq-enqueue' determines
  304.      where the answer ends.
  305.      The return value of `tq-enqueue' itself is not meaningful.
  306.  - Function: tq-close QUEUE
  307.      Shut down transaction queue QUEUE, waiting for all pending
  308.      transactions to complete, and then terminate the connection or
  309.      child process.
  310.    Transaction queues are implemented by means of a filter function.
  311. *Note Filter Functions::.
  312. File: elisp,  Node: Network,  Prev: Transaction Queues,  Up: Processes
  313. Network Connections
  314. ===================
  315.    Emacs Lisp programs can open TCP network connections to other
  316. processes on the same machine or other machines.  A network connection
  317. is handled by Lisp much like a subprocess, and is represented by a
  318. process object.  However, the process you are communicating with is not
  319. a child of the Emacs process, so you can't kill it or send it signals.
  320. All you can do is send and receive data.  `delete-process' closes the
  321. connection, but does not kill the process at the other end; that
  322. process must decide what to do about closure of the connection.
  323.    You can distinguish process objects representing network connections
  324. from those representing subprocesses with the `process-status'
  325. function.  It always returns either `open' or `closed' for a network
  326. connection, and it never returns either of those values for a real
  327. subprocess.  *Note Process Information::.
  328.  - Function: open-network-stream NAME BUFFER-OR-NAME HOST SERVICE
  329.      This function opens a TCP connection for a service to a host.  It
  330.      returns a process object to represent the connection.
  331.      The NAME argument specifies the name for the process object.  It
  332.      is modified as necessary to make it unique.
  333.      The BUFFER-OR-NAME argument is the buffer to associate with the
  334.      connection.  Output from the connection is inserted in the buffer,
  335.      unless you specify a filter function to handle the output.  If
  336.      BUFFER-OR-NAME is `nil', it means that the connection is not
  337.      associated with any buffer.
  338.      The arguments HOST and SERVICE specify where to connect to; HOST
  339.      is the host name (a string), and SERVICE is the name of a defined
  340.      network service (a string) or a port number (an integer).
  341. File: elisp,  Node: System Interface,  Next: Display,  Prev: Processes,  Up: Top
  342. Operating System Interface
  343. **************************
  344.    This chapter is about starting and getting out of Emacs, access to
  345. values in the operating system environment, and terminal input, output,
  346. and flow control.
  347.    *Note Building Emacs::, for related information.  See also *Note
  348. Display::, for additional operating system status information
  349. pertaining to the terminal and the screen.
  350. * Menu:
  351. * Starting Up::         Customizing Emacs start-up processing.
  352. * Getting Out::         How exiting works (permanent or temporary).
  353. * System Environment::  Distinguish the name and kind of system.
  354. * User Identification:: Finding the name and user id of the user.
  355. * Time of Day::        Getting the current time.
  356. * Time Conversion::     Converting a time from numeric form to a string, or
  357.                           to calendrical data (or vice versa).
  358. * Timers::        Setting a timer to call a function at a certain time.
  359. * Terminal Input::      Recording terminal input for debugging.
  360. * Terminal Output::     Recording terminal output for debugging.
  361. * Special Keysyms::     Defining system-specific key symbols for X windows.
  362. * Flow Control::        How to turn output flow control on or off.
  363. * Batch Mode::          Running Emacs without terminal interaction.
  364. File: elisp,  Node: Starting Up,  Next: Getting Out,  Up: System Interface
  365. Starting Up Emacs
  366. =================
  367.    This section describes what Emacs does when it is started, and how
  368. you can customize these actions.
  369. * Menu:
  370. * Start-up Summary::        Sequence of actions Emacs performs at start-up.
  371. * Init File::               Details on reading the init file (`.emacs').
  372. * Terminal-Specific::       How the terminal-specific Lisp file is read.
  373. * Command Line Arguments::  How command line arguments are processed,
  374.                               and how you can customize them.
  375. File: elisp,  Node: Start-up Summary,  Next: Init File,  Up: Starting Up
  376. Summary: Sequence of Actions at Start Up
  377. ----------------------------------------
  378.    The order of operations performed (in `startup.el') by Emacs when it
  379. is started up is as follows:
  380.   1. It loads the initialization library for the window system, if you
  381.      are using a window system.  This library's name is
  382.      `term/WINDOWSYSTEM-win.el'.
  383.   2. It processes the initial options.  (Some of them are handled even
  384.      earlier than this.)
  385.   3. It initializes the X window frame and faces, if appropriate.
  386.   4. It runs the normal hook `before-init-hook'.
  387.   5. It loads the library `site-start', unless the option
  388.      `-no-site-file' was specified.  The library's file name is usually
  389.      `site-start.el'.
  390.   6. It loads the file `~/.emacs' unless `-q' was specified on the
  391.      command line.  (This is not done in `-batch' mode.)  The `-u'
  392.      option can specify the user name whose home directory should be
  393.      used instead of `~'.
  394.   7. It loads the library `default' unless `inhibit-default-init' is
  395.      non-`nil'.  (This is not done in `-batch' mode or if `-q' was
  396.      specified on the command line.)  The library's file name is
  397.      usually `default.el'.
  398.   8. It runs the normal hook `after-init-hook'.
  399.   9. It sets the major mode according to `initial-major-mode', provided
  400.      the buffer `*scratch*' is still current and still in Fundamental
  401.      mode.
  402.  10. It loads the terminal-specific Lisp file, if any, except when in
  403.      batch mode or using a window system.
  404.  11. It displays the initial echo area message, unless you have
  405.      suppressed that with `inhibit-startup-echo-area-message'.
  406.  12. It processes the action arguments from the command line.
  407.  13. It runs `term-setup-hook'.
  408.  14. It calls `frame-notice-user-settings', which modifies the
  409.      parameters of the selected frame according to whatever the init
  410.      files specify.
  411.  15. It runs `window-setup-hook'.  *Note Window Systems::.
  412.  16. It displays copyleft, nonwarranty, and basic use information,
  413.      provided there were no remaining command line arguments (a few
  414.      steps above) and the value of `inhibit-startup-message' is `nil'.
  415.  - User Option: inhibit-startup-message
  416.      This variable inhibits the initial startup messages (the
  417.      nonwarranty, etc.).  If it is non-`nil', then the messages are not
  418.      printed.
  419.      This variable exists so you can set it in your personal init file,
  420.      once you are familiar with the contents of the startup message.
  421.      Do not set this variable in the init file of a new user, or in a
  422.      way that affects more than one user, because that would prevent
  423.      new users from receiving the information they are supposed to see.
  424.  - User Option: inhibit-startup-echo-area-message
  425.      This variable controls the display of the startup echo area
  426.      message.  You can suppress the startup echo area message by adding
  427.      text with this form to your `.emacs' file:
  428.           (setq inhibit-startup-echo-area-message
  429.                 "YOUR-LOGIN-NAME")
  430.      Simply setting `inhibit-startup-echo-area-message' to your login
  431.      name is not sufficient to inhibit the message; Emacs explicitly
  432.      checks whether `.emacs' contains an expression as shown above.
  433.      Your login name must appear in the expression as a Lisp string
  434.      constant.
  435.      This way, you can easily inhibit the message for yourself if you
  436.      wish, but thoughtless copying of your `.emacs' file will not
  437.      inhibit the message for someone else.
  438. File: elisp,  Node: Init File,  Next: Terminal-Specific,  Prev: Start-up Summary,  Up: Starting Up
  439. The Init File: `.emacs'
  440. -----------------------
  441.    When you start Emacs, it normally attempts to load the file `.emacs'
  442. from your home directory.  This file, if it exists, must contain Lisp
  443. code.  It is called your "init file".  The command line switches `-q'
  444. and `-u' affect the use of the init file; `-q' says not to load an init
  445. file, and `-u' says to load a specified user's init file instead of
  446. yours.  *Note Entering Emacs: (emacs)Entering Emacs.
  447.    A site may have a "default init file", which is the library named
  448. `default.el'.  Emacs finds the `default.el' file through the standard
  449. search path for libraries (*note How Programs Do Loading::.).  The
  450. Emacs distribution does not come with this file; sites may provide one
  451. for local customizations.  If the default init file exists, it is
  452. loaded whenever you start Emacs, except in batch mode or if `-q' is
  453. specified.  But your own personal init file, if any, is loaded first; if
  454. it sets `inhibit-default-init' to a non-`nil' value, then Emacs does
  455. not subsequently load the `default.el' file.
  456.    Another file for site-customization is `site-start.el'.  Emacs loads
  457. this *before* the user's init file.  You can inhibit the loading of
  458. this file with the option `-no-site-file'.
  459.  - Variable: site-run-file
  460.      This variable specifies the site-customization file to load before
  461.      the user's init file.  Its normal value is `"site-start"'.
  462.    If there is a great deal of code in your `.emacs' file, you should
  463. move it into another file named `SOMETHING.el', byte-compile it (*note
  464. Byte Compilation::.), and make your `.emacs' file load the other file
  465. using `load' (*note Loading::.).
  466.    *Note Init File Examples: (emacs)Init File Examples, for examples of
  467. how to make various commonly desired customizations in your `.emacs'
  468. file.
  469.  - User Option: inhibit-default-init
  470.      This variable prevents Emacs from loading the default
  471.      initialization library file for your session of Emacs.  If its
  472.      value is non-`nil', then the default library is not loaded.  The
  473.      default value is `nil'.
  474.  - Variable: before-init-hook
  475.  - Variable: after-init-hook
  476.      These two normal hooks are run just before, and just after,
  477.      loading of the user's init file, `default.el', and/or
  478.      `site-start.el'.
  479. File: elisp,  Node: Terminal-Specific,  Next: Command Line Arguments,  Prev: Init File,  Up: Starting Up
  480. Terminal-Specific Initialization
  481. --------------------------------
  482.    Each terminal type can have its own Lisp library that Emacs loads
  483. when run on that type of terminal.  For a terminal type named TERMTYPE,
  484. the library is called `term/TERMTYPE'.  Emacs finds the file by
  485. searching the `load-path' directories as it does for other files, and
  486. trying the `.elc' and `.el' suffixes.  Normally, terminal-specific Lisp
  487. library is located in `emacs/lisp/term', a subdirectory of the
  488. `emacs/lisp' directory in which most Emacs Lisp libraries are kept.
  489.    The library's name is constructed by concatenating the value of the
  490. variable `term-file-prefix' and the terminal type.  Normally,
  491. `term-file-prefix' has the value `"term/"'; changing this is not
  492. recommended.
  493.    The usual function of a terminal-specific library is to enable
  494. special keys to send sequences that Emacs can recognize.  It may also
  495. need to set or add to `function-key-map' if the Termcap entry does not
  496. specify all the terminal's function keys.  *Note Terminal Input::.
  497.    When the name of the terminal type contains a hyphen, only the part
  498. of the name before the first hyphen is significant in choosing the
  499. library name.  Thus, terminal types `aaa-48' and `aaa-30-rv' both use
  500. the `term/aaa' library.  If necessary, the library can evaluate
  501. `(getenv "TERM")' to find the full name of the terminal type.
  502.    Your `.emacs' file can prevent the loading of the terminal-specific
  503. library by setting the variable `term-file-prefix' to `nil'.  This
  504. feature is useful when experimenting with your own peculiar
  505. customizations.
  506.    You can also arrange to override some of the actions of the
  507. terminal-specific library by setting the variable `term-setup-hook'.
  508. This is a normal hook which Emacs runs using `run-hooks' at the end of
  509. Emacs initialization, after loading both your `.emacs' file and any
  510. terminal-specific libraries.  You can use this variable to define
  511. initializations for terminals that do not have their own libraries.
  512. *Note Hooks::.
  513.  - Variable: term-file-prefix
  514.      If the `term-file-prefix' variable is non-`nil', Emacs loads a
  515.      terminal-specific initialization file as follows:
  516.           (load (concat term-file-prefix (getenv "TERM")))
  517.      You may set the `term-file-prefix' variable to `nil' in your
  518.      `.emacs' file if you do not wish to load the
  519.      terminal-initialization file.  To do this, put the following in
  520.      your `.emacs' file: `(setq term-file-prefix nil)'.
  521.  - Variable: term-setup-hook
  522.      This variable is a normal hook that Emacs runs after loading your
  523.      `.emacs' file, the default initialization file (if any) and the
  524.      terminal-specific Lisp file.
  525.      You can use `term-setup-hook' to override the definitions made by a
  526.      terminal-specific file.
  527.    See `window-setup-hook' in *Note Window Systems::, for a related
  528. feature.
  529. File: elisp,  Node: Command Line Arguments,  Prev: Terminal-Specific,  Up: Starting Up
  530. Command Line Arguments
  531. ----------------------
  532.    You can use command line arguments to request various actions when
  533. you start Emacs.  Since you do not need to start Emacs more than once
  534. per day, and will often leave your Emacs session running longer than
  535. that, command line arguments are hardly ever used.  As a practical
  536. matter, it is best to avoid making the habit of using them, since this
  537. habit would encourage you to kill and restart Emacs unnecessarily
  538. often.  These options exist for two reasons: to be compatible with
  539. other editors (for invocation by other programs) and to enable shell
  540. scripts to run specific Lisp programs.
  541.    This section describes how Emacs processes command line arguments,
  542. and how you can customize them.
  543.  - Function: command-line
  544.      This function parses the command line that Emacs was called with,
  545.      processes it, loads the user's `.emacs' file and displays the
  546.      startup messages.
  547.  - Variable: command-line-processed
  548.      The value of this variable is `t' once the command line has been
  549.      processed.
  550.      If you redump Emacs by calling `dump-emacs', you may wish to set
  551.      this variable to `nil' first in order to cause the new dumped Emacs
  552.      to process its new command line arguments.
  553.  - Variable: command-switch-alist
  554.      The value of this variable is an alist of user-defined command-line
  555.      options and associated handler functions.  This variable exists so
  556.      you can add elements to it.
  557.      A "command line option" is an argument on the command line of the
  558.      form:
  559.           -OPTION
  560.      The elements of the `command-switch-alist' look like this:
  561.           (OPTION . HANDLER-FUNCTION)
  562.      The HANDLER-FUNCTION is called to handle OPTION and receives the
  563.      option name as its sole argument.
  564.      In some cases, the option is followed in the command line by an
  565.      argument.  In these cases, the HANDLER-FUNCTION can find all the
  566.      remaining command-line arguments in the variable
  567.      `command-line-args-left'.  (The entire list of command-line
  568.      arguments is in `command-line-args'.)
  569.      The command line arguments are parsed by the `command-line-1'
  570.      function in the `startup.el' file.  See also *Note Command Line
  571.      Switches and Arguments: (emacs)Command Switches.
  572.  - Variable: command-line-args
  573.      The value of this variable is the list of command line arguments
  574.      passed to Emacs.
  575.  - Variable: command-line-functions
  576.      This variable's value is a list of functions for handling an
  577.      unrecognized command-line argument.  Each time the next argument
  578.      to be processed has no special meaning, the functions in this list
  579.      are called, in order of appearance, until one of them returns a
  580.      non-`nil' value.
  581.      These functions are called with no arguments.  They can access the
  582.      command-line argument under consideration through the variable
  583.      `argi'.  The remaining arguments (not including the current one)
  584.      are in the variable `command-line-args-left'.
  585.      When a function recognizes and processes the argument in `argi', it
  586.      should return a non-`nil' value to say it has dealt with that
  587.      argument.  If it has also dealt with some of the following
  588.      arguments, it can indicate that by deleting them from
  589.      `command-line-args-left'.
  590.      If all of these functions return `nil', then the argument is used
  591.      as a file name to visit.
  592. File: elisp,  Node: Getting Out,  Next: System Environment,  Prev: Starting Up,  Up: System Interface
  593. Getting Out of Emacs
  594. ====================
  595.    There are two ways to get out of Emacs: you can kill the Emacs job,
  596. which exits permanently, or you can suspend it, which permits you to
  597. reenter the Emacs process later.  As a practical matter, you seldom kill
  598. Emacs--only when you are about to log out.  Suspending is much more
  599. common.
  600. * Menu:
  601. * Killing Emacs::        Exiting Emacs irreversibly.
  602. * Suspending Emacs::     Exiting Emacs reversibly.
  603. File: elisp,  Node: Killing Emacs,  Next: Suspending Emacs,  Up: Getting Out
  604. Killing Emacs
  605. -------------
  606.    Killing Emacs means ending the execution of the Emacs process.  The
  607. parent process normally resumes control.  The low-level primitive for
  608. killing Emacs is `kill-emacs'.
  609.  - Function: kill-emacs &optional EXIT-DATA
  610.      This function exits the Emacs process and kills it.
  611.      If EXIT-DATA is an integer, then it is used as the exit status of
  612.      the Emacs process.  (This is useful primarily in batch operation;
  613.      see *Note Batch Mode::.)
  614.      If EXIT-DATA is a string, its contents are stuffed into the
  615.      terminal input buffer so that the shell (or whatever program next
  616.      reads input) can read them.
  617.    All the information in the Emacs process, aside from files that have
  618. been saved, is lost when the Emacs is killed.  Because killing Emacs
  619. inadvertently can lose a lot of work, Emacs queries for confirmation
  620. before actually terminating if you have buffers that need saving or
  621. subprocesses that are running.  This is done in the function
  622. `save-buffers-kill-emacs'.
  623.  - Variable: kill-emacs-query-functions
  624.      After asking the standard questions, `save-buffers-kill-emacs'
  625.      calls the functions in the list `kill-buffer-query-functions', in
  626.      order of appearance, with no arguments.  These functions can ask
  627.      for additional confirmation from the user.  If any of them returns
  628.      non-`nil', Emacs is not killed.
  629.  - Variable: kill-emacs-hook
  630.      This variable is a normal hook; once `save-buffers-kill-emacs' is
  631.      finished with all file saving and confirmation, it runs the
  632.      functions in this hook.
  633. File: elisp,  Node: Suspending Emacs,  Prev: Killing Emacs,  Up: Getting Out
  634. Suspending Emacs
  635. ----------------
  636.    "Suspending Emacs" means stopping Emacs temporarily and returning
  637. control to its superior process, which is usually the shell.  This
  638. allows you to resume editing later in the same Emacs process, with the
  639. same buffers, the same kill ring, the same undo history, and so on.  To
  640. resume Emacs, use the appropriate command in the parent shell--most
  641. likely `fg'.
  642.    Some operating systems do not support suspension of jobs; on these
  643. systems, "suspension" actually creates a new shell temporarily as a
  644. subprocess of Emacs.  Then you would exit the shell to return to Emacs.
  645.    Suspension is not useful with window systems such as X, because the
  646. Emacs job may not have a parent that can resume it again, and in any
  647. case you can give input to some other job such as a shell merely by
  648. moving to a different window.  Therefore, suspending is not allowed
  649. when Emacs is an X client.
  650.  - Function: suspend-emacs STRING
  651.      This function stops Emacs and returns control to the superior
  652.      process.  If and when the superior process resumes Emacs,
  653.      `suspend-emacs' returns `nil' to its caller in Lisp.
  654.      If STRING is non-`nil', its characters are sent to be read as
  655.      terminal input by Emacs's superior shell.  The characters in
  656.      STRING are not echoed by the superior shell; only the results
  657.      appear.
  658.      Before suspending, `suspend-emacs' runs the normal hook
  659.      `suspend-hook'.  In Emacs version 18, `suspend-hook' was not a
  660.      normal hook; its value was a single function, and if its value was
  661.      non-`nil', then `suspend-emacs' returned immediately without
  662.      actually suspending anything.
  663.      After the user resumes Emacs, `suspend-emacs' runs the normal hook
  664.      `suspend-resume-hook'.  *Note Hooks::.
  665.      The next redisplay after resumption will redraw the entire screen,
  666.      unless the variable `no-redraw-on-reenter' is non-`nil' (*note
  667.      Refresh Screen::.).
  668.      In the following example, note that `pwd' is not echoed after
  669.      Emacs is suspended.  But it is read and executed by the shell.
  670.           (suspend-emacs)
  671.                => nil
  672.           (add-hook 'suspend-hook
  673.                     (function (lambda ()
  674.                                 (or (y-or-n-p
  675.                                       "Really suspend? ")
  676.                                     (error "Suspend cancelled")))))
  677.                => (lambda nil
  678.                     (or (y-or-n-p "Really suspend? ")
  679.                         (error "Suspend cancelled")))
  680.           (add-hook 'suspend-resume-hook
  681.                     (function (lambda () (message "Resumed!"))))
  682.                => (lambda nil (message "Resumed!"))
  683.           (suspend-emacs "pwd")
  684.                => nil
  685.           ---------- Buffer: Minibuffer ----------
  686.           Really suspend? `y'
  687.           ---------- Buffer: Minibuffer ----------
  688.           ---------- Parent Shell ----------
  689.           lewis@slug[23] % /user/lewis/manual
  690.           lewis@slug[24] % fg
  691.           ---------- Echo Area ----------
  692.           Resumed!
  693.  - Variable: suspend-hook
  694.      This variable is a normal hook run before suspending.
  695.  - Variable: suspend-resume-hook
  696.      This variable is a normal hook run after suspending.
  697. File: elisp,  Node: System Environment,  Next: User Identification,  Prev: Getting Out,  Up: System Interface
  698. Operating System Environment
  699. ============================
  700.    Emacs provides access to variables in the operating system
  701. environment through various functions.  These variables include the
  702. name of the system, the user's UID, and so on.
  703.  - Variable: system-type
  704.      The value of this variable is a symbol indicating the type of
  705.      operating system Emacs is operating on.  Here is a table of the
  706.      possible values:
  707.     `aix-v3'
  708.           AIX.
  709.     `berkeley-unix'
  710.           Berkeley BSD.
  711.     `dgux'
  712.           Data General DGUX operating system.
  713.     `gnu'
  714.           A GNU system (using the GNU kernel, which consists of the
  715.           HURD and Mach).
  716.     `gnu/linux'
  717.           A variant GNU system using the Linux kernel.
  718.     `hpux'
  719.           Hewlett-Packard HPUX operating system.
  720.     `irix'
  721.           Silicon Graphics Irix system.
  722.     `ms-dos'
  723.           Microsoft MS-DOS "operating system."
  724.     `next-mach'
  725.           NeXT Mach-based system.
  726.     `rtu'
  727.           Masscomp RTU, UCB universe.
  728.     `unisoft-unix'
  729.           UniSoft UniPlus.
  730.     `usg-unix-v'
  731.           AT&T System V.
  732.     `vax-vms'
  733.           VAX VMS.
  734.     `windows-nt'
  735.           Microsoft windows NT.
  736.     `xenix'
  737.           SCO Xenix 386.
  738.      We do not wish to add new symbols to make finer distinctions
  739.      unless it is absolutely necessary!  In fact, we hope to eliminate
  740.      some of these alternatives in the future.  We recommend using
  741.      `system-configuration' to distinguish between different operating
  742.      systems.
  743.  - Variable: system-configuration
  744.      This variable holds the three-part configuration name for the
  745.      hardware/software configuration of your system, as a string.  The
  746.      convenient way to test parts of this string is with `string-match'.
  747.  - Function: system-name
  748.      This function returns the name of the machine you are running on.
  749.           (system-name)
  750.                => "prep.ai.mit.edu"
  751.    The symbol `system-name' is a variable as well as a function.  In
  752. fact, the function returns whatever value the variable `system-name'
  753. currently holds.  Thus, you can set the variable `system-name' in case
  754. Emacs is confused about the name of your system.  The variable is also
  755. useful for constructing frame titles (*note Frame Titles::.).
  756.  - Variable: mail-host-address
  757.      If this variable is non-`nil', it is used instead of `system-name'
  758.      for purposes of generating email addresses.  For example, it is
  759.      used when constructing the default value of `user-mail-address'.
  760.      *Note User Identification::.  (Since this is done when Emacs
  761.      starts up, the value actually used is the one saved when Emacs was
  762.      dumped.  *Note Building Emacs::.)
  763.  - Function: getenv VAR
  764.      This function returns the value of the environment variable VAR,
  765.      as a string.  Within Emacs, the environment variable values are
  766.      kept in the Lisp variable `process-environment'.
  767.           (getenv "USER")
  768.                => "lewis"
  769.           
  770.           lewis@slug[10] % printenv
  771.           PATH=.:/user/lewis/bin:/usr/bin:/usr/local/bin
  772.           USER=lewis
  773.           TERM=ibmapa16
  774.           SHELL=/bin/csh
  775.           HOME=/user/lewis
  776.  - Command: setenv VARIABLE VALUE
  777.      This command sets the value of the environment variable named
  778.      VARIABLE to VALUE.  Both arguments should be strings.  This
  779.      function works by modifying `process-environment'; binding that
  780.      variable with `let' is also reasonable practice.
  781.  - Variable: process-environment
  782.      This variable is a list of strings, each describing one environment
  783.      variable.  The functions `getenv' and `setenv' work by means of
  784.      this variable.
  785.           process-environment
  786.           => ("l=/usr/stanford/lib/gnuemacs/lisp"
  787.               "PATH=.:/user/lewis/bin:/usr/class:/nfsusr/local/bin"
  788.               "USER=lewis"
  789.           "TERM=ibmapa16"
  790.               "SHELL=/bin/csh"
  791.               "HOME=/user/lewis")
  792.  - Variable: path-separator
  793.      This variable holds a string which says which character separates
  794.      directories in a search path (as found in an environment
  795.      variable).  Its value is `":"' for Unix and GNU systems, and `";"'
  796.      for MS-DOS and Windows NT.
  797.  - Variable: invocation-name
  798.      This variable holds the program name under which Emacs was
  799.      invoked.  The value is a string, and does not include a directory
  800.      name.
  801.  - Variable: invocation-directory
  802.      This variable holds the directory from which the Emacs executable
  803.      was invoked, or perhaps `nil' if that directory cannot be
  804.      determined.
  805.  - Variable: installation-directory
  806.      If non-`nil', this is a directory within which to look for the
  807.      `lib-src' and `etc' subdirectories.  This is non-`nil' when Emacs
  808.      can't find those directories in their standard installed
  809.      locations, but can find them in a directory related somehow to the
  810.      one containing the Emacs executable.
  811.  - Function: load-average
  812.      This function returns the current 1-minute, 5-minute and 15-minute
  813.      load averages in a list.  The values are integers that are 100
  814.      times the system load averages.  (The load averages indicate the
  815.      number of processes trying to run.)
  816.           (load-average)
  817.                => (169 48 36)
  818.           
  819.           lewis@rocky[5] % uptime
  820.            11:55am  up 1 day, 19:37,  3 users,
  821.            load average: 1.69, 0.48, 0.36
  822.  - Function: emacs-pid
  823.      This function returns the process ID of the Emacs process.
  824.  - Function: setprv PRIVILEGE-NAME &optional SETP GETPRV
  825.      This function sets or resets a VMS privilege.  (It does not exist
  826.      on Unix.)  The first arg is the privilege name, as a string.  The
  827.      second argument, SETP, is `t' or `nil', indicating whether the
  828.      privilege is to be turned on or off.  Its default is `nil'.  The
  829.      function returns `t' if successful, `nil' otherwise.
  830.      If the third argument, GETPRV, is non-`nil', `setprv' does not
  831.      change the privilege, but returns `t' or `nil' indicating whether
  832.      the privilege is currently enabled.
  833. File: elisp,  Node: User Identification,  Next: Time of Day,  Prev: System Environment,  Up: System Interface
  834. User Identification
  835. ===================
  836.  - Variable: user-mail-address
  837.      This holds the nominal email address of the user who is using
  838.      Emacs.  Emacs normally sets this variable to a default value after
  839.      reading your init files, but not if you have already set it.  So
  840.      you can set the variable to some other value in your `~/.emacs'
  841.      file if you do not want to use the default value.
  842.  - Function: user-login-name &optional UID
  843.      If you don't specify UID, this function returns the name under
  844.      which the user is logged in.  If the environment variable `LOGNAME'
  845.      is set, that value is used.  Otherwise, if the environment variable
  846.      `USER' is set, that value is used.  Otherwise, the value is based
  847.      on the effective UID, not the real UID.
  848.      If you specify UID, the value is the user name that corresponds to
  849.      UID (which should be an integer).
  850.           (user-login-name)
  851.                => "lewis"
  852.  - Function: user-real-login-name
  853.      This function returns the user name corresponding to Emacs's real
  854.      UID.  This ignores the effective UID and ignores the environment
  855.      variables `LOGNAME' and `USER'.
  856.  - Function: user-full-name
  857.      This function returns the full name of the user.
  858.           (user-full-name)
  859.                => "Bil Lewis"
  860.    The symbols `user-login-name', `user-real-login-name' and
  861. `user-full-name' are variables as well as functions.  The functions
  862. return the same values that the variables hold.  These variables allow
  863. you to "fake out" Emacs by telling the functions what to return.  The
  864. variables are also useful for constructing frame titles (*note Frame
  865. Titles::.).
  866.  - Function: user-real-uid
  867.      This function returns the real UID of the user.
  868.           (user-real-uid)
  869.                => 19
  870.  - Function: user-uid
  871.      This function returns the effective UID of the user.
  872. File: elisp,  Node: Time of Day,  Next: Time Conversion,  Prev: User Identification,  Up: System Interface
  873. Time of Day
  874. ===========
  875.    This section explains how to determine the current time and the time
  876. zone.
  877.  - Function: current-time-string &optional TIME-VALUE
  878.      This function returns the current time and date as a
  879.      humanly-readable string.  The format of the string is unvarying;
  880.      the number of characters used for each part is always the same, so
  881.      you can reliably use `substring' to extract pieces of it.  It is
  882.      wise to count the characters from the beginning of the string
  883.      rather than from the end, as additional information may be added
  884.      at the end.
  885.      The argument TIME-VALUE, if given, specifies a time to format
  886.      instead of the current time.  The argument should be a list whose
  887.      first two elements are integers.  Thus, you can use times obtained
  888.      from `current-time' (see below) and from `file-attributes' (*note
  889.      File Attributes::.).
  890.           (current-time-string)
  891.                => "Wed Oct 14 22:21:05 1987"
  892.  - Function: current-time
  893.      This function returns the system's time value as a list of three
  894.      integers: `(HIGH LOW MICROSEC)'.  The integers HIGH and LOW
  895.      combine to give the number of seconds since 0:00 January 1, 1970,
  896.      which is HIGH * 2**16 + LOW.
  897.      The third element, MICROSEC, gives the microseconds since the
  898.      start of the current second (or 0 for systems that return time
  899.      only on the resolution of a second).
  900.      The first two elements can be compared with file time values such
  901.      as you get with the function `file-attributes'.  *Note File
  902.      Attributes::.
  903.  - Function: current-time-zone &optional TIME-VALUE
  904.      This function returns a list describing the time zone that the
  905.      user is in.
  906.      The value has the form `(OFFSET NAME)'.  Here OFFSET is an integer
  907.      giving the number of seconds ahead of UTC (east of Greenwich).  A
  908.      negative value means west of Greenwich.  The second element, NAME
  909.      is a string giving the name of the time zone.  Both elements
  910.      change when daylight savings time begins or ends; if the user has
  911.      specified a time zone that does not use a seasonal time
  912.      adjustment, then the value is constant through time.
  913.      If the operating system doesn't supply all the information
  914.      necessary to compute the value, both elements of the list are
  915.      `nil'.
  916.      The argument TIME-VALUE, if given, specifies a time to analyze
  917.      instead of the current time.  The argument should be a cons cell
  918.      containing two integers, or a list whose first two elements are
  919.      integers.  Thus, you can use times obtained from `current-time'
  920.      (see above) and from `file-attributes' (*note File Attributes::.).
  921.